/*
  Copyright (c) 2011, Mikheev Rostislav
  Copyright (c) 2011, FreshFarsh team

  Steel Engine source code is free software; you can redistribute it and/or
  modify it under the terms of the GNU General Public License
  as published by the Free Software Foundation; either version 2
  of the License, or (at your option) any later version.

  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.

  You should have received a copy of the GNU General Public License
  along with this program; if not, write to the Free Software
  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
*/
/**
  core.h

  @author Mikheev Rostislav <hacenator@gmail.com>
  @date 23.03.2011
  @brief GUI basic layer class header file
*/

#ifndef STEEL_GUI_CORE_H_
#define STEEL_GUI_CORE_H_

#include <stdint.h>
#include "GL/glew.h"
#include "common.h"
#include "structures.h"
#include "exception.h"
#include "basic_class.h"
#include "texture.h"
#include "listener.h"
#include "window_manager.h"
#include "gui/font.h"

namespace _STEEL_NAMESPACE {

class GUILayer:
  public BasicClass,
  public IMouseListener,
  public IWindowListener,
  public IKeyboardListener {
 public:
  explicit GUILayer(const WindowManager *window);
  GUILayer(const WindowManager *window, int width, int height);

  ~GUILayer();

  void SetSize(int width, int height);

  /// Draw additional informations like fps and other on GUI layer
  bool info() {
    return _draw_info;
  }

  /// Set additional info drawing on GUI layer
  bool set_info(bool value) {
    _draw_info = value;
  }

  GUIFont * font() {
    return _font;
  }

 private:
  void SetupView(); ///< Setup perspecive and viewport

  // listener interfaces
  void OnKeyUp(int key) {};
  void OnKeyDown(int key);
  void OnMouseMove(int x, int y);
  void OnMouseUp(int x, int y, int button) { };
  void OnMouseDown(int x, int y, int button) { };
  void OnInit();
  void OnDraw();
  void OnTerminate() { };

  int _width; ///< GUI layer width
  int _height; ///< GUI layer height

  // resources
  WindowManager *_window; ///< GUI render context
  Texture *_cursor; ///< UI cursor
  GUIFont *_font; ///< default font

  // options
  bool _draw_info; ///< draw additional info flag

  // OpenGl
  GLint _viewport[4]; ///< current viewport
  Matrix4x4d _projection_matrix; ///< projection matrix
  Matrix4x4d _model_matrix; ///< projection matrix

  // Control
  int _mouse_x, _mouse_y; ///< mouse coordinates

};

}
#endif // STEEL_GUI_CORE_H_
